<template>
  <div>

    <div>
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="180px" class="demo-ruleForm">
        <!-- <div class="title">基础设置</div>
        <el-form-item label="是否开启分佣">
          <el-switch v-model="ruleForm.open" active-color="#13ce66">
          </el-switch>
        </el-form-item>
        <el-form-item label="分销层级" prop="level" v-if="ruleForm.open">
          <el-radio-group v-model="ruleForm.level">
            <el-radio :label="1">一级分销</el-radio>
            <el-radio :label="2">二级分销</el-radio>
          </el-radio-group>
        </el-form-item> -->
        <div class="title">分销提现设置</div>
        <el-form-item label="最小提现额度" prop="min_extract">
          <!-- <el-input maxlength="15" v-model="ruleForm.min_extract" class="input">
          </el-input> -->
          <el-input-number v-model="ruleForm.min_extract" :precision="2" controls-position="right" :min="0"></el-input-number>
        </el-form-item>
        <el-form-item label="最大提现额度" prop="max_extract">
          <!-- <el-input maxlength="15" v-model="ruleForm.max_extract" class="input">
          </el-input> -->
          <el-input-number v-model="ruleForm.max_extract" :precision="2" controls-position="right" :min="0"></el-input-number>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import serviceApione from '@/api/serviceApione.js'
export default {
  data () {
    return {
      ruleForm: {
        open: false
      },
      rules: {
        level: [{
          required: true,
          message: '请选择分销层级',
          trigger: 'blur'
        }],
        min_extract: [{
          required: true,
          message: '请输入最小提取额度',
          trigger: 'blur'
        }],
        max_extract: [{
          required: true,
          message: '请输入最大提取额度',
          trigger: 'blur'
        }]
      }
    }
  },
  created () {
    this.loadInfo()
  },
  methods: {
    // 查询
    loadInfo () {
      serviceApione.searchDistributionconfig().then(res => {
        if (res.data && res.data.code == 200) {
          if (res.data.data) {
            this.ruleForm = res.data.data
          }
        }
      })
    },

    // 保存
    submitForm (e) {
      this.$refs[e].validate((valid) => {
        if (valid) {
          serviceApione.setDistributionconfig(this.ruleForm).then(res => {
            if (res.data && res.data.code == 200) {
              this.$message.success('设置成功！')
            }
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    }
  }
}
</script>

<style scoped>
.title {
  padding-left: 20px;
  border-left: 4px solid #15a193;
  font-size: 16px;
  margin: 15px 0;
}

.input {
  width: 222px;
}
</style>
